window.onload = function () {
    $(".order-name").text("项目：笑傲江湖影院-订单编号：" + localStorage.getItem("orderId"));
    $(".amount-price").text(localStorage.getItem("price"));
}

// 点击付款按钮时， 判断是微信支付还是支付宝支付
$("#btu").click(function () {
    let val = $(".payment-list input[name='zffs']:checked").val();
    if (val == "wx") {
        $("#sys").show();
        return;
    }

    let user = JSON.parse(sessionStorage.getItem("user"));
    let orderId = localStorage.getItem("orderId");
    let price = localStorage.getItem("price");
    let orderName = "用户" + user.userId + "的订单";

    localStorage.setItem("successOrderId", orderId);
    window.location = "http://localhost:8080/cinema/api/AlipayServlet.do?orderId=" + orderId + "&price=" + price + "&orderName=" + orderName;
});



// 微信支付 点击 "已付款" 按钮时 ，修改订单状态为已支付状态
$("#success").click(function () {
    let oid = {
        orderId: localStorage.getItem("orderId")
    }

    // 付款成功后，修改订单状态
    $.ajax({
        url: 'http://localhost:8080/cinema/api/UpdateOrderStatusByIdServlet.do',
        type: 'put',
        data: JSON.stringify(oid),
        dataType: 'json',
        success: function (dto) {
            if (dto.code == 200) {
                $.cookie("djsendtime", null);

                layer.msg(dto.value, { icon: 1, time: 1000 }, function () {
                    window.location = "home_myOrder.html";
                });
            } else {
                layer.msg(dto.msg, { icon: 5 });
            }
        }

    });

    $("#sys").hide();
});

// 关闭弹出层按钮
$("#close-sys").click(function () {
    $("#sys").hide();
});


// 超时关闭提示框
$(".ok-btn").click(function () {
    $(".hide-prompt").hide();
    window.location = "home_filmInfo.html";
});

